<%@ page language="java" pageEncoding="UTF-8"
	errorPage="../../defaultException.jsp"%>
<%@include file="../../tags.jsp"%>
<html>
<head>
<title>目的地交通管理</title>
<%@include file="../../head.jsp"%>

</head>
<body>


	<table id="list_data" cellspacing="0" cellpadding="0">
		<thead>
			<tr>
				<th field="info" formatter="trafficInfo">查看三级交通信息</th>
				<th field="name">交通名称</th>
				<th field="enname">英文名称</th>
				<th field="trafficType" formatter="renderTrafficType">交通类型</th>
				<th field="lat">纬度</th>
				<th field="lng">经度</th>
				<th field="content">特色描述</th>

			</tr>
		</thead>
	</table>
	<script type="text/javascript">
		var trafficType = {
			'1' : '航空',
			'2' : '铁路',
			'3' : '公路',
			'4' : '水运',
			'5' : '市内交通'
		};
		function renderTrafficType(value, row, index) {
			return trafficType[value];
		}

		function trafficInfo(value,row,index){
		  return "<a href='${cpath }/admin/dest/traffic/level3/vlist?destId=${dest.destId}&trafficL1Id=${traffic.trafficId}&trafficL2Id="
			+ row.trafficId + "'>查看三级交通信息</a>";
		  }
	</script>

	<div id="addDestFeatureDialog"
		style="width: 400px; height: 280px; padding: 10px 20px" closed="true">
	</div>

	<script type="text/javascript">
		$('#list_data')
				.datagrid(
						{
							title : '<a href=${cpath }/admin/dest/vlist>目的地</a>&gt&gt'+
							'<a href=${cpath }/admin/dest/traffic/level1/vlist?destId=${dest.destId}><c:out value="${dest.zhname}" escapeXml="true"/></a>&gt&gt${traffic.name}',
							iconCls : 'icon-edit',//图标 
							width : 1024,
							height : 500,
							doSize : true,
							nowrap : false,
							striped : true,
							border : true,
							collapsible : false,//是否可折叠的 
							fitColumns : true,//自动大小 
							fit : false,
							url : '${cpath }/admin/dest/traffic/level2/list?parentId=${traffic.trafficId}',
							//sortName: 'code', 
							//sortOrder: 'desc', 
							remoteSort : false,
							idField : 'trafficId',
							singleSelect : true,//是否单选 
							pagination : false,//分页控件 
							rownumbers : true,//行号 
							//frozenColumns:[[ 
							//    {field:'ck',checkbox:true} 
							//]], 
							toolbar : [
									{
										text : '添加交通',
										iconCls : 'icon-add',
										handler : function() {
											var saveAction = cpath
													+ '/admin/dest/traffic/level2/save?parentId=${traffic.trafficId}&trafficType=${traffic.trafficType}&destId=${dest.destId}';
											var openAction = cpath
													+ '/admin/dest/traffic/level2/vsave';
											openAddDestinationDialog('添加交通',
													openAction, saveAction,
													addDestTrafficSuccess);
										}
									},
									'-',
									{
										text : '修改交通',
										iconCls : 'icon-add',
										handler : function() {
											var saveAction = cpath
													+ '/admin/dest/traffic/level2/update';
											var openAction = cpath
													+ '/admin/dest/traffic/level2/vupdate';
											openAddDestinationDialog('修改交通',
													openAction, saveAction,
													addDestTrafficSuccess,
													getSelectDestTraffic);
										}
									},
									'-',
									{
										text : '删除交通',
										iconCls : 'icon-remove',
										handler : function() {
											var deleteAction = cpath
													+ '/admin/dest/traffic/level2/delete';
											deleteDestTraffic(deleteAction,
													getSelectDestTraffic);
										}
									}, '-', {
										text : '刷新',
										iconCls : 'icon-reload',
										handler : function() {
											$('#list_data').datagrid('reload');
											save_status = false;
										}
									} ]
						});
	</script>
	<script type="text/javascript">
		var url;
		var cpath = '${cpath}';

		function getSelectDestTraffic() {
			return $('#list_data').datagrid('getSelected');
		}

		function addDestTrafficSuccess() {
			$('#list_data').datagrid('reload'); // reload the user data
		}

		function openAddDestinationDialog(dlgtitle, openAction, saveAction,
				addDestTrafficSuccess, getSelectDest) {

			if (getSelectDest) {
				var row = getSelectDest();
				//没有选中行，则需要提示
				if (!row) {
					$.messager.alert("提示", "请选择一条交通信息", "info");
					return;
				} else {
					//选中了一行需在saveAction后加上目的地编号
					openAction += "?trafficId=" + row.trafficId;
				}
			}

			$('#addDestFeatureDialog').dialog({
				title : dlgtitle,
				width : 800,
				height : 400,
				closed : false,
				cache : false,
				resizable : true,
				href : openAction,
				modal : true,
				closed : true,
				buttons : [ {
					text : '保存',
					iconCls : "icon-ok",
					handler : function() {
						saveForm(saveAction, addDestTrafficSuccess);
					}
				}, {
					text : '取消',
					iconCls : "icon-cancel",
					handler : function() {
						$('#addDestFeatureDialog').dialog('close');
					}
				} ]
			});
			$('#addDestFeatureDialog').dialog('open');
		}
		var save_status = false;
		function saveForm(saveAction, addDestTrafficSuccess) {
			if (save_status) {
				$.messager.alert("提示", "请耐心等待。。。后台执行中。。。", "info");
				return;
			}
			save_status = true;
			$('#fm').form('submit', {
				url : saveAction,
				onSubmit : function() {
					var result = $(this).form('validate');
					if (!result) {
						save_status = false;
					}
					return result;
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.resultCode !== '00000000') {
						$.messager.alert("错误", result.resultMsg, "error");
						$('#list_data').datagrid('clearSelections');
					} else {
						$.messager.alert("成功", result.resultMsg, "info");
						$('#addDestFeatureDialog').dialog('close');
						if (addDestTrafficSuccess) {
							addDestTrafficSuccess();
						}
						$('#list_data').datagrid('clearSelections');
					}
					save_status = false;
				}
			});
		}

		function deleteDestTraffic(deleteAction, getSelectDestTraffic) {
			//添加信息，需要是否有前置条件
			if (getSelectDestTraffic) {

				var row = getSelectDestTraffic();
				//没有选中行，则需要提示
				if (!row) {
					$.messager.alert("提示", "请选择要删除的交通信息！", "info");
					return;
				}
				if (row) {
					$.messager.confirm("提示", "确认要删除这条交通信息吗？", function(r) {
						if (r) {
							$.post(deleteAction, row,
									function(result) {
										if (result.resultCode === '00000000') {
											$('#list_data').datagrid('reload'); // reload the user data
											$.messager.alert("提示",
													result.resultMsg, "info");
											$('#list_data').datagrid(
													'clearSelections');
										} else {
											$.messager.alert("错误",
													result.resultMsg, "error");
											$('#list_data').datagrid(
													'clearSelections');
										}
									}, 'json');
						}
					});
				}
			}
		}
	</script>
	<style type="text/css">
#fm {
	margin: 0;
	padding: 40px 40px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 90px;
}
</style>
</body>
</html>